package com.example.core.tag;

import com.example.sys.module.mode.SysColumnInfo;
import com.example.sys.module.mode.SysModuleInfo;
import com.example.sys.module.service.SysModuleService;
import com.example.utils.SpringUtils;
import com.example.utils.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.ServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import java.util.List;

public class XTd extends BodyTagSupport {

    Logger logger = LoggerFactory.getLogger(getClass());

    public SysModuleService sysModuleService;

    private String titleWidth = "15%";

    private String propertyName;

    private String colspan;

    private String width = "35%";

    private Boolean required = false;

    private String placeholder;

    public SysModuleService getSysModuleService() {
        if (sysModuleService == null) {
            sysModuleService = (SysModuleService) SpringUtils.getBean(SysModuleService.class);
        }
        return sysModuleService;
    }

    @Override
    public int doStartTag() throws JspException {
        JspWriter out = pageContext.getOut();
        ServletRequest httpRequest = pageContext.getRequest();
        String entityName = (String) httpRequest.getAttribute("entityName");
        if (!StringUtils.isEmpty(entityName)) {
            SysModuleInfo sysModuleInfo = this.getSysModuleService().getSysModuleInfoBySimpleName(entityName);
            if (sysModuleInfo != null){
                List<SysColumnInfo> columnInfos = sysModuleInfo.getColumnInfos();

            }
        }
        return super.doStartTag();
    }

    @Override
    public int doEndTag() throws JspException {
        JspWriter out = pageContext.getOut();
        return super.doEndTag();
    }
}
